package com.magenta.maxoptra.gis.service;

import com.magenta.maxoptra.gis.commons.Logger;
import com.magenta.maxoptra.gis.*;
import com.magenta.maxoptra.gis.ConnectionPool;
import com.magenta.maxoptra.gis.GeoProviderSettings;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;

/**
 * Абстрагирует пользователя от деталей получения провайдера
 *
 * @author Zaur Muhametgaleev
 * @version 12/14/11 9:24 AM
 * @see "jira task MRS-4127: Add support of YourNavigation.Org routing provider"
 * @since Maxoptra 3 (GT)
 */
@Stateless(name = GeoProviderFacade.JNDI_NAME)
@Local(GeoProviderFacade.class)
public class GeoProviderFacadeImpl implements GeoProviderFacade {
    @EJB
    ConnectionPool connPool;

    @EJB
    AccessToGeoProvider geoProvidersCache;

    private Logger logger = new Logger(getClass());

    @Override
    public IGeocoding getGeoCoder(GeoProviderSettings settings) {
        Long connectionId = connPool.getConnectionId(settings);
        return geoProvidersCache.getGeocodingProvider(connectionId);
    }

    @Override
    public IGeoRouting getGeoRouter(GeoProviderSettings settings) {
        Long connectionId = connPool.getConnectionId(settings);
        return geoProvidersCache.getGeoRoutingProvider(connectionId);
    }

    @Override
    public IReverseGeocoding getReverseGeocodingProvider(GeoProviderSettings settings) {
        Long connectionId = connPool.getConnectionId(settings);
        return geoProvidersCache.getReverseGeocodingProvider(connectionId);
    }
}
